import { setdistricircuit, settingdistribution } from "@/utils/method.js"

export default {
  methods: {
    getcircuitdata(e) { // 发布子组件传来的
      this.submit = true
      this.setCiruit = e
      this.setcircuitdata()
    },
    setcircuitdata() {
      // 代理价
      let b = parseFloat(this.money.money_proxy)
      this.setCiruit.agency_price = b.toFixed(2) * 1

      // 市场价
      let c = parseFloat(this.money.market_price)
      this.setCiruit.market_reference_price = c.toFixed(2) * 1

      // 第三方导游
      let d = parseFloat(this.money.other_guide_cost)
      this.setCiruit.other_guide_cost = d.toFixed(2) * 1

      // 删除异常数据
      this.$delete(this.setCiruit, 'other_guide_service_fee')

      this.setCiruit.channel_sales = 0
      this.setCiruit.total_channel_sales = 0
      this.setCiruit.is_open_application = 0
      this.setCiruit.status = 1
      this.setCiruit.status_text = "审核中"
      this.tabelData.push(this.setCiruit)
      // console.log();
    },
    // 分销发布线路
    showpublic() {
      // console.log(this.setCiruit);
      // console.log(this.money);
      setdistricircuit(this.setCiruit).then((res) => {
        // console.log(res);
        if (res.data.code == 4000) {
          this.$message.error(res.data.msg + "🧐")
        } else if (res.data.code == 0) {
          this.$message({ message: "提交成功请耐心等待 😊", type: "success" })

          this.index = 0
          this.money = {}
        }
      })
        .catch((error) => {
          console.log(error);
          this.$message.error(error.data.msg)
        });
      this.cancel()
    },
    // 样式变动
    cancel() {
      this.submit = false
      this.$refs.circuit.submit = false
    },
    // 修改switch 的值
    is_open(val) {
      let a = {}
      a.distribution_id = val.distribution_id
      a.is_open_application = val.is_open_application
      console.log(a);
      settingdistribution(a).then(() => {
        // console.log(res)
        if (a.is_open_application == 1) {
          this.$notification({
            message: "已开放分销申请 😊", type: "success"
          })
        } else {
          this.$notification({
            message: "已关闭分销申请 😊", type: "warning"
          })
        }

      })
        .catch((error) => {
          console.log(error);
          this.$message.error(error.data.msg)
        });
    }
  },
}